﻿using NUnit.Framework;
using System.Collections.Generic;
namespace ThunkC_.Collections_
{
    #region Sample
    /// <summary>
    /// 
    /// </summary>
    public class SampleEqualityComparer : EqualityComparer<string>
    {
        /// <summary>
        /// When overridden in a derived class, determines whether two objects of type <paramref name="T"/> are equal.
        /// </summary>
        /// <param name="x">The first object to compare.</param>
        /// <param name="y">The second object to compare.</param>
        /// <returns>
        /// true if the specified objects are equal; otherwise, false.
        /// </returns>
        public override bool Equals(string x, string y)
        {
            return (x == y);
        }
        /// <summary>
        /// When overridden in a derived class, serves as a hash function for the specified object for hashing algorithms and data structures, such as a hash table.
        /// </summary>
        /// <param name="obj">The object for which to get a hash code.</param>
        /// <returns>A hash code for the specified object.</returns>
        /// <exception cref="T:System.ArgumentNullException">
        /// The type of <paramref name="obj"/> is a reference type and <paramref name="obj"/> is null.
        /// </exception>
        public override int GetHashCode(string obj)
        {
            return 1;
        }
    }
    #endregion Sample

    /// <summary>
    /// EqualityComparerFixture
    /// </summary>
    [TestFixture]
    public class EqualityComparerFixture
    {
        [Test]
        public void Constructor_Valid_NotNull()
        {
            var comparer = new SampleEqualityComparer();
            Assert.IsNotNull(comparer);
        }

        [Test]
        public void Equals_Valid_EqualsTrue()
        {
            var comparer = new SampleEqualityComparer();
            Assert.IsTrue(comparer.Equals("test", "test"));
        }

        [Test]
        public void GetHashCode_Valid_NotEqualZero()
        {
            var comparer = new SampleEqualityComparer();
            Assert.AreNotEqual(0, comparer.GetHashCode("test"));
        }

        [Test]
        public void getDefault_Valid_NotNull()
        {
            Assert.IsNotNull(EqualityComparer<string>.Default);
        }
    }
}
